//
//  PLDirectorySearcher.h
//  Plankton
//
//  Created by Marc Schlichte on 16.06.09.
//  Copyright 2009 Framework Labs. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "PLDirectory.h"		// for directory delegate

@protocol PLDirectorySearcherDelegate;

/// A class which helps in finding other actors of a given service by a simple interface.
/// It uses and configures a PLDirectory internally an registers as a delegate of that directory.
///
@interface PLDirectorySearcher : NSObject <PLDirectoryDelegate>
{
	PLDirectory						*directory;
	id<PLDirectorySearcherDelegate>	delegate;
	NSMutableSet					*foundAids;
	NSMutableSet					*discoveredAids;
	NSString						*serviceToSearch;
	BOOL							searchAgain;
}

- (id)initWithPlatform:(PLPlatform *)platform;

@property(nonatomic, assign) id<PLDirectorySearcherDelegate> delegate;

- (BOOL)startSearchAidsForService:(NSString *)service;
- (BOOL)stopSearchAids;

@property(nonatomic, readonly) NSSet *foundAids;

@end

/// The name of the notification sent when the set of found actor ids has changed.
/// The userInfo dictionary contains two keys @"found" and @"lost" as with the same sets 
/// as when using the delegate approach.
///
extern NSString *const PLDirectorySearcherDidChangeNotification;

/// Instead of using notifications, a client could adopt this delegate protocol to get
/// informed about changes in the set of found actor ids.
///
@protocol PLDirectorySearcherDelegate <NSObject>

- (void)directorySearcher:(PLDirectorySearcher *)searcher found:(NSSet *)newAids lost:(NSSet *)oldAids;

@end